import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-04
 * Time: 9:38
 */
public class test1 {
    /**
     * LeetCode 判断是否互为字符重排
     */

    public boolean CheckPermutation(String s1, String s2) {
        if(s1.length()!=s2.length()){
            return false;
        }
        int[] hash = new int[128];
        for(int i=0;i<s1.length();i++){
            hash[s1.charAt(i)]++;
        }
        for(int i=0;i<s2.length();i++){
            hash[s2.charAt(i)]--;
            if(hash[s2.charAt(i)]<0){
                return false;
            }
        }
        return true;
    }


    public boolean CheckPermutation1(String s1, String s2) {
        if(s1.length()!=s2.length()){
            return false;
        }
        Map<Character,Integer> hash = new HashMap<>();
        for(int i=0;i<s1.length();i++){
            hash.put(s1.charAt(i),hash.getOrDefault(s1.charAt(i),0)+1);
        }
        for(int i=0;i<s2.length();i++){
            hash.put(s2.charAt(i),hash.getOrDefault(s2.charAt(i),0)-1);
        }
        for(int val:hash.values()){
            if(val!=0){
                return false;
            }
        }
        return true;
    }
}
